package com.bsoft.medicalserver.controller;

import com.bsoft.medicalserver.pojo.*;
import com.google.gson.Gson;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin(origins="*",maxAge=3600)
public class MedicalServerController {
    private static final String split = "^";
    @RequestMapping("/Business_Handle")
    public BusinessHandleResponse businessHandle (@RequestBody BusinessHandleRequest request) {
        BusinessHandleResponse response = new BusinessHandleResponse();
        String res = "";
        //业务编号
        String ywbh = "";
        String requestPara = request.getInputData();
        if (StringUtils.hasLength(requestPara)) {
            ywbh = requestPara.substring(0, requestPara.indexOf(split));
        } else {
            new RuntimeException("入参不能为空！");
        }

        switch (ywbh) {
            //建立就诊档案
            case "2210":
                res = "2210^1004^ZJJS^20210323075858-1004-0000ZJJS-9685|330100^20210323135603122852627-1004-ZJJS^0^M81983738|11|20210323135603|N92.600|月经失调||204||YB200433110330411791130542|钱莉莉|ZJJS|11032112|||||^1^\n" +
                        "20210323135340-1004-5516^1^11||^";
                break;
            //就诊档案修改
            case "2230":
                res = "2230";
                break;
            //撤销就诊档案
            case "2240":
                res = "2240";
                break;
            //自费人员就诊档案上传
            case "3410":
                res = "3410";
                break;
            //自费人员处方明细上报(3420)
            case "3420":
                res = "3420";
                break;
            // 上传自费信息确认交易(3430)
            case "3430":
                res = "3430";
                break;
            //处方明细上报(2310)
            case "2310":
                res = "2310^1004^ZJJS^20210323075858-1004-0000ZJJS-9685|330100^20210323135604135337391-1004-ZJJS^000000^M81983738|1|11|C23749472|C30187909|20210323135609|6685|八珍益母胶囊|z040300009270002|19.5100|4.0000|78.04||0.28g*36粒|盒||0||0|4|19.51|盒  |口服|3.00|11|1|1|0600|妇女保健部(妇科)|YB200433110330411791130542|钱莉莉|ZJJS|||0|$M81983738|1|12|C23749445|C30187888|20210323135527|6053|右归胶囊|z010904003530002|39.0200|5.0000|195.10||0.45g*36粒|盒||0||0|5|39.02|盒  |口服|4.00|11|1|1|0600|妇女保健部(妇科)|YB200433110330411791130542|钱莉莉|ZJJS|||0|^1^\\n\" +\n" +
                        "                        \"20210323135340-1004-5557^1^M81983738|C23749472|C30187909|78.04|0.0|0.0|11|1|0|0.0|19.51||$M81983738|C23749445|C30187888|195.1|5.853|0.0|12|2|0|0.03|39.02||$^";
                break;
            // 处方明细撤销(2320)
            case "2320":
                res = "2320";
                break;
            // 外配处方上报(2330)
            case "2330":
                res = "2330";
                break;
            // 费用预结算(2420)
            case "2420":
                res = "2420^1004^ZJJS^20210323075858-1004-0000ZJJS-9685^20210323135604272971046-1004-ZJJS^000000^M81983738|9009465153|11|20210323135604|20210323135604|3|0|N92.600|月经失调|N92.600||||||||||||||273.14|ZJJS||||11032112|^1^\n" +
                        "20210323135340-1004-5594^1^1004|11032112|M81983738|9009465153|1|20210323135604272971046-1004-ZJJS|20210323135340-1004-5594|273.14|52.09|0.0|0.0|52.09|221.05|215.2|5.85|0.0|0.0|0.0|0.0|0|421.42|0.0|0.0|0.0|20210323135604|20210323075858-1004-0000ZJJS-9685|202103231355511591|0.0|0.0|0.0|0.0|0.0|0.0|0.0|215.2||5.85|0.0|0.0|0.0|215.2|0.0|0.0|0.0|0.0|0.0|0.0|0.0|^";
                break;
            // 费用结算(2410)
            case "2410":
                res = "2410^1004^ZJJS^20210323075858-1004-0000ZJJS-9685^20210323135622137004547-1004-ZJJS^0^M81983738|9009465153|11|20210323135604|20210323135604|3|0|N92.600|月经失调|N92.600||||||||||||||273.14|ZJJS||||11032112|^1^\n" +
                        "20210323135400-1004-1609^1^1004|11032112|M81983738|9009465153|1|20210323135622137004547-1004-ZJJS|20210323135400-1004-1609|273.14|52.09|0.0|0.0|52.09|221.05|215.2|5.85|0.0|0.0|0.0|0.0|0|421.42|0.0|0.0|0.0|20210323135604|20210323075858-1004-0000ZJJS-9685|202103231356112444|0.0|0.0|0.0|0.0|0.0|0.0|0.0|215.2||5.85|0.0|0.0|0.0|215.2|0.0|0.0|0.0|0.0|0.0|0.0|0.0|^";
                break;
            // 退费交易(2430)
            case "2430":
                res = "2430";
                break;
            // 获取结算单(2440)
            case "2440":
                res = "2440";
                break;
            case "err":
                res = "{ReCode\";\"-2\",\" ReData\";\"^^医疗待遇类别为少年儿童的人员,不能享受医疗类另戏的待遇,请重新选擇医疗类别!^返回值:θ,错误句柄值:0x31e70000,FILE:DynamicRequest\\EapagentEx,cpp,LIN:221\"}";
                break;
            default:
                res = "业务编号输入错误，请核对！";
                break;
        }
        response.setResponseText(res);
        return response;
    }

    @RequestMapping("/ICC_Transaction")
    public ICCTransactionResponse ICCTransaction (@RequestBody ICCTransactionRequest request) {
        //入参
        String inputData = request.getInputData();
        //返回参
        ICCTransactionResponse response = new ICCTransactionResponse();
        String outputData = "";
        Gson gson = new Gson();
        ICCTransactionObj iccTransactionObj = gson.fromJson(inputData, ICCTransactionObj.class);
        Integer transNum = iccTransactionObj.getTransNum();
        switch (transNum) {
            case 1113:
                outputData = "330100D1560000050144913DE278370D|3|W33840648|331003199309110038|蔡宇|1|||||339900906360|";
                break;
            case 1116:
                outputData = "330100D1560000050118F7BE45D33780|3|W49142836|410185199405154515|贺晓龙|1||||||02|2806060870733737332|2088022287889185";
                break;
            default:
                outputData = "业务编码输入有误！";
                break;
        }
        response.setOutputData(outputData);
        return response;
    }

    @RequestMapping("/ICC_GetDZPZ_Info")
    public ICCGetDZPZInfoResponse ICCGetDZPZInfo (@RequestBody ICCGetDZPZInfoRequest request) {
        //入参
        String dataIn = request.getDataIn();
        String outData = StringUtils.hasLength(dataIn) ? "张三|330106201208154029|31|639900D15600000500BF7C7A48FB4966|330100|" : "电子凭证DZPZ令牌输入有误！";
        ICCGetDZPZInfoResponse response = new ICCGetDZPZInfoResponse();
        response.setDataOut(outData);
        return response;
    }
}
